package com.wxchat.chat.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.wxchat.chat.util.DBUtils;

public class Dao {

	Connection connection = null;
	PreparedStatement preparedStatement = null;
	ResultSet resultSet = null;
	String name = null;
	/**
	 * 查询数据方法
	 */
	public String select(String sql, Object[] obj) {
		try {
			connection = DBUtils.getConnection();
			preparedStatement = connection.prepareStatement(sql);
			for (int i = 0; i < obj.length; i++) {
				preparedStatement.setObject(i + 1, obj[i]);
			}
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				name = resultSet.getString("nickname");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DBUtils.colse(connection, resultSet, preparedStatement);
		}
		return name;
	}

	/**
	 * 修改的方法
	 */
	public boolean addOrUpdata(String sql, Object[] obj) {
		return DBUtils.executeSQL(sql, obj);
	}
}
